home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / clients / editres / widgets.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-12  |  26.3 KB  |  856 lines

  1. /*
  2.  * $XConsortium: widgets.c,v 1.20 92/02/11 11:44:24 dave Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  */
  23.  
  24. /*
  25.  * Code for creating all widgets used by EditRes.
  26.  */
  27.  
  28. #include <stdio.h>
  29. #ifdef MSDOS
  30. #include "X11/Intrinsc.h"      /* QDK 05/11/1994 12:54pm. */
  31. #else
  32. #include "X11/Intrinsic.h"
  33. #endif
  34. #include <X11/StringDefs.h>    /* Get standard string definations. */
  35.  
  36. #include <X11/Xaw/AsciiText.h>
  37. #include <X11/Xaw/Box.h>    
  38. #include <X11/Xaw/Cardinals.h>    
  39. #include <X11/Xaw/Label.h>    
  40. #include <X11/Xaw/List.h>    
  41. #include <X11/Xaw/MenuButton.h>    
  42. #include <X11/Xaw/Paned.h>    
  43. #include <X11/Xaw/Panner.h>    
  44. #include <X11/Xaw/Porthole.h>    
  45. #include <X11/Xaw/SmeBSB.h>    
  46. #include <X11/Xaw/SmeLine.h>    
  47. #include <X11/Xaw/SimpleMenu.h>    
  48. #include <X11/Xaw/Toggle.h>    
  49. #include <X11/Xaw/Tree.h>
  50. #include <X11/Xaw/Viewport.h>    
  51.  
  52. #include "editresP.h"
  53.  
  54. /*
  55.  * functions.
  56.  */
  57.  
  58. static void CreateResourceNameForm(), SetToggleGroupLeaders(), CreateLists();
  59. static void CreateCommandMenu(), CreateTreeCommandMenu(), FreeClientData();
  60. static void FreeResBox(), CreateValueWidget(), PopupOnNode();
  61. static Widget CreateTopArea();
  62. static void MakeBoxLookNice();
  63.  
  64. extern void GetResourceList(), AnyChosen(), SetResourceString();
  65. extern void PannerCallback(), PortholeCallback(), DumpTreeToFile();
  66. extern void Quit(), SendTree(), FlashActiveWidgets();
  67. extern void TreeSelect(), TreeRelabel(), TreeActivate(), FindWidget();
  68. extern void ResourceListCallback(), PopdownResBox(), SaveResource();
  69. extern void GetNamesAndClasses(), ApplyResource(), ActivateResourceWidgets();
  70. extern void ActivateWidgetsAndSetResourceString(), SetFile();
  71.  
  72. extern void InitSetValues();
  73.  
  74. /*    Function Name: BuildWidgetTree
  75.  *    Description: Creates all widgets for Editres.
  76.  *    Arguments: parent - the shell to put them into.
  77.  *    Returns: none.
  78.  */
  79.  
  80. void 
  81. BuildWidgetTree(parent)
  82. Widget parent;
  83. {
  84.     Widget paned, porthole, panner;
  85.  
  86.     paned = XtCreateManagedWidget("paned", panedWidgetClass, parent,
  87.                   NULL, ZERO);
  88.  
  89.     panner = CreateTopArea(paned);
  90.  
  91.     porthole = XtCreateManagedWidget("porthole", portholeWidgetClass,
  92.                      paned, NULL, ZERO);
  93.  
  94. /*
  95.  * Allow the panner and porthole to talk to each other.
  96.  */
  97.  
  98.     XtAddCallback(porthole, 
  99.           XtNreportCallback, PortholeCallback, (XtPointer) panner);
  100.     XtAddCallback(panner, 
  101.           XtNreportCallback, PannerCallback, (XtPointer) porthole);
  102.  
  103.     global_tree_parent = porthole;
  104. }
  105.  
  106. /*    Function Name: CreateTopArea
  107.  *    Description: Creates the top part of the display
  108.  *    Arguments: parent - widget to put this menu bar into.
  109.  *    Returns: none. 
  110.  */
  111.  
  112. static Widget
  113. CreateTopArea(parent)
  114. Widget parent;
  115. {
  116.     Widget box, panner, pane;
  117.  
  118.     box = XtCreateManagedWidget("box", boxWidgetClass, parent, NULL, ZERO);
  119.  
  120.     CreateCommandMenu(box);
  121.     CreateTreeCommandMenu(box);
  122.  
  123.     pane = XtCreateManagedWidget("hPane", panedWidgetClass, parent, NULL,ZERO);
  124.  
  125.     {
  126.     panner = XtCreateManagedWidget("panner", pannerWidgetClass, 
  127.                        pane, NULL, ZERO);
  128.     global_screen_data.info_label = XtCreateManagedWidget("userMessage", 
  129.                                  labelWidgetClass,
  130.                                  pane, NULL, ZERO);
  131.     }
  132.     return(panner);
  133. }
  134.  
  135. /*    Function Name: CreateCommandMenu
  136.  *    Description: Creats the command menu.
  137.  *    Arguments: parent - widget to put this menu into.
  138.  *    Returns: none.
  139.  */
  140.  
  141. static void
  142. CreateCommandMenu(parent)
  143. Widget parent;
  144. {
  145.     Widget menu, entry, button;
  146.  
  147.     button = XtCreateManagedWidget("commands", menuButtonWidgetClass, parent,
  148.                    NULL, ZERO);
  149.  
  150.     menu = XtCreatePopupShell("menu", simpleMenuWidgetClass, button,
  151.                   NULL, ZERO);
  152.     
  153.     entry = XtCreateManagedWidget("sendTree", smeBSBObjectClass, menu,
  154.                     NULL, ZERO);
  155.     XtAddCallback(entry, XtNcallback, SendTree, (XtPointer) TRUE);
  156.  
  157.     entry = XtCreateManagedWidget("refreshTree", smeBSBObjectClass, menu,
  158.                   NULL, ZERO);
  159.     XtAddCallback(entry, XtNcallback, SendTree, (XtPointer) FALSE);
  160.  
  161.     entry = XtCreateManagedWidget("dumpTreeToFile", smeBSBObjectClass, menu,
  162.                     NULL, ZERO);
  163.     XtAddCallback(entry, XtNcallback, DumpTreeToFile, NULL);
  164.  
  165.     entry = XtCreateManagedWidget("line", smeLineObjectClass, menu,
  166.                   NULL, ZERO);
  167.     entry= XtCreateManagedWidget("getResourceList", smeBSBObjectClass, menu,
  168.                  NULL, ZERO);
  169.     XtAddCallback(entry, XtNcallback, GetResourceList, NULL);
  170.  
  171.     entry = XtCreateManagedWidget("setValues", smeBSBObjectClass, menu,
  172.                     NULL, ZERO);
  173.     XtAddCallback(entry, XtNcallback, InitSetValues, NULL);
  174.  
  175.     entry = XtCreateManagedWidget("line", smeLineObjectClass, menu,
  176.                   NULL, ZERO);
  177.  
  178.     entry = XtCreateManagedWidget("quit", smeBSBObjectClass, menu,
  179.                     NULL, ZERO);
  180.     XtAddCallback(entry, XtNcallback, Quit, NULL);
  181.  
  182. }
  183.  
  184. /*    Function Name: CreateTreeCommandMenu
  185.  *    Description: Creats the command menu.
  186.  *    Arguments: parent - widget to put this menu into.
  187.  *    Returns: none.
  188.  */
  189.  
  190. #define SELECT 0
  191. #define ACTIVATE 1
  192. #define LABEL 2
  193. #define LINE 3
  194. #define FIND 4
  195. #define FLASH 5
  196.  
  197. struct tree_ops_menu {
  198.     char * name;
  199.     int type;
  200.     XtPointer data;
  201. };
  202.  
  203. static void
  204. CreateTreeCommandMenu(parent)
  205. Widget parent;
  206. {
  207.     Widget menu, button, entry;
  208.     int i, number;
  209.     static struct tree_ops_menu tree_menu[] = {
  210.     { "showClientWidget", FIND, (XtPointer) NULL },
  211.         { "selectAll", SELECT, (XtPointer) SelectAll },
  212.     { "unselectAll", SELECT, (XtPointer) SelectNone },
  213.     { "invertAll", SELECT, (XtPointer) SelectInvert },
  214.     { "line", LINE, (XtPointer) NULL },
  215.     { "selectChildren", SELECT, (XtPointer) SelectChildren },
  216.         { "selectParent", SELECT, (XtPointer) SelectParent },
  217.     { "selectDescendants", SELECT, (XtPointer) SelectDescendants },
  218.         { "selectAncestors", SELECT, (XtPointer) SelectAncestors },
  219.         { "line", LINE, (XtPointer) NULL },
  220.         { "showWidgetNames", LABEL, (XtPointer) NameLabel },
  221.         { "showClassNames", LABEL, (XtPointer) ClassLabel },
  222.         { "showWidgetIDs", LABEL, (XtPointer) IDLabel},
  223.         { "showWidgetWindows", LABEL, (XtPointer) WindowLabel },
  224.         { "line", LINE, (XtPointer) NULL },
  225.     { "flashActiveWidgets", FLASH, (XtPointer) NULL }
  226.     };
  227.  
  228.     button = XtCreateManagedWidget("treeCommands", menuButtonWidgetClass,
  229.                    parent, NULL, ZERO);
  230.  
  231.     menu = XtCreatePopupShell("menu", simpleMenuWidgetClass, button,
  232.                   NULL, ZERO);
  233.  
  234.     for ( i = 0, number = XtNumber(tree_menu) ; i < number ; i++) {
  235.     void (*func)();
  236.     WidgetClass class = smeBSBObjectClass;
  237.  
  238.     switch (tree_menu[i].type) {
  239.     case SELECT:
  240.         func = TreeSelect;
  241.         break;
  242.     case LABEL:
  243.         func = TreeRelabel;
  244.         break;
  245.     case LINE:
  246.         func = NULL;
  247.         class = smeLineObjectClass;
  248.         break;
  249.     case FIND:
  250.         func = FindWidget;
  251.         break;
  252.     case FLASH:
  253.         func = FlashActiveWidgets;
  254.         break;
  255.     default:
  256.         continue;
  257.     }
  258.  
  259.     entry = XtCreateManagedWidget(tree_menu[i].name, class, menu,
  260.                       NULL, ZERO);
  261.     if (func != NULL) 
  262.         XtAddCallback(entry, XtNcallback, func, tree_menu[i].data);
  263.     }
  264. }
  265.  
  266. static Pixmap old_pixmap;
  267.  
  268. /*    Function Name: PrepareToLayoutTree
  269.  *    Description: prepares the Tree widget to be layed out.
  270.  *    Arguments: tree - the Tree widget.
  271.  *    Returns: none
  272.  */
  273.  
  274. void
  275. PrepareToLayoutTree(tree)
  276. Widget tree;
  277. {
  278.     Arg args[1];
  279.  
  280.     XtSetArg(args[0], XtNbackgroundPixmap, &old_pixmap);
  281.     XtGetValues(XtParent(tree), args, ONE);
  282.  
  283.     XtSetArg(args[0], XtNbackgroundPixmap, None);
  284.     XtSetValues(XtParent(tree), args, ONE);
  285.  
  286.     XtUnmapWidget(tree);
  287. }
  288.  
  289. /*    Function Name: LayoutTree
  290.  *    Description: Laysout the tree widget.
  291.  *    Arguments: tree - the widget tree.
  292.  *    Returns: none.
  293.  */
  294.  
  295. void
  296. LayoutTree(tree)
  297. Widget tree;
  298. {
  299.     Arg args[1];
  300.     
  301.     XawTreeForceLayout(tree);
  302.     XtMapWidget(tree); 
  303.  
  304.     XtSetArg(args[0], XtNbackgroundPixmap, old_pixmap);
  305.     XtSetValues(XtParent(tree), args, ONE);
  306. }
  307.  
  308. /************************************************************
  309.  *
  310.  * Functions for creating the Resource Box.
  311.  *
  312.  ************************************************************/
  313.  
  314. /*    Function Name: CreateResourceBoxWidgets
  315.  *    Description: Creates the widgets that make up the resource box.
  316.  *    Arguments: node - the widget node.
  317.  *                 names - the list of names that make up the normal resources.
  318.  *                 cons_names - the list of names that make up 
  319.  *                              the constraint resources. 
  320.  *    Returns: none.
  321.  */
  322.  
  323. void
  324. CreateResourceBoxWidgets(node, names, cons_names)
  325. WNode * node;
  326. char **names, **cons_names;
  327. {
  328.     Widget pane, box, button;
  329.     ResourceBoxInfo * res_box;
  330.  
  331.     res_box = (ResourceBoxInfo *) XtMalloc(sizeof(ResourceBoxInfo));
  332.     node->resources->res_box = res_box;
  333.  
  334.     res_box->shell = XtCreatePopupShell(RESOURCE_BOX,
  335.                     transientShellWidgetClass,
  336.                     node->widget, NULL, ZERO);
  337.     XtAddCallback(res_box->shell, XtNdestroyCallback,
  338.           FreeResBox, (XtPointer) node);
  339.  
  340.     pane = XtCreateManagedWidget("pane", panedWidgetClass, 
  341.                  res_box->shell, NULL, ZERO);
  342.  
  343.     res_box->res_label = XtCreateManagedWidget("resourceLabel", 
  344.                            labelWidgetClass, 
  345.                            pane, NULL, ZERO);
  346.  
  347.     CreateResourceNameForm(pane, node);
  348.     CreateLists(pane, node, names, cons_names);
  349.     CreateValueWidget(pane, node);
  350.  
  351.     XtSetKeyboardFocus(pane, res_box->value_wid); /* send keyboard to value. */
  352.  
  353.     box = XtCreateManagedWidget("commandBox", boxWidgetClass,
  354.                  pane, NULL, ZERO);
  355.  
  356.     button = XtCreateManagedWidget("setFile", commandWidgetClass,
  357.                    box, NULL, ZERO);
  358.     XtAddCallback(button, XtNcallback, SetFile, NULL);
  359.  
  360.     button = XtCreateManagedWidget("save", commandWidgetClass,
  361.                    box, NULL, ZERO);
  362.     XtAddCallback(button, XtNcallback, SaveResource,(XtPointer) res_box);
  363.  
  364.     button = XtCreateManagedWidget("apply", commandWidgetClass,
  365.                    box, NULL, ZERO);
  366.     XtAddCallback(button, XtNcallback, ApplyResource,(XtPointer) node);
  367.  
  368.     button = XtCreateManagedWidget("saveAndApply", commandWidgetClass,
  369.                    box, NULL, ZERO);
  370.     XtAddCallback(button, XtNcallback, SaveResource,(XtPointer) res_box);
  371.     XtAddCallback(button, XtNcallback, ApplyResource,(XtPointer) node);
  372.  
  373.     button = XtCreateManagedWidget("cancel", commandWidgetClass,
  374.                    box, NULL, ZERO);
  375.     XtAddCallback(button,XtNcallback,PopdownResBox,(XtPointer)res_box->shell);
  376.  
  377.     SetToggleGroupLeaders(node);
  378.     PopupOnNode(node, res_box->shell);
  379. }
  380.  
  381. /*    Function Name: CreateResourceNameForm
  382.  *    Description: Creates the Form widget with children that represent
  383.  *                   the full resource name for this object.
  384.  *    Arguments: parent - parent of the form.
  385.  *                 node - the node corrosponding to this object.
  386.  *    Returns: none
  387.  */
  388.  
  389. static void
  390. CreateResourceNameForm(parent, node)
  391. Widget parent;
  392. WNode * node;
  393. {
  394.     ResourceBoxInfo * res_box = node->resources->res_box;
  395.     AnyInfo *new_info, *old_info;
  396.     char **names, **classes;
  397.     Widget form;
  398.     NameInfo * name_info = NULL;
  399.     Cardinal num_args;
  400.     Arg args[10];
  401.     int i;
  402.     Widget dot, star, name, class, single, any;
  403.  
  404.     GetNamesAndClasses(node, &names, &classes);
  405.  
  406.     form = XtCreateManagedWidget("namesAndClasses", formWidgetClass,
  407.                  parent, NULL, ZERO);
  408.  
  409.     name = class = any = NULL;
  410.     i = 0;
  411.     old_info = NULL;
  412.     while (TRUE) {
  413.  
  414.     num_args = 0;
  415.     XtSetArg(args[num_args], XtNfromHoriz, name); num_args++;
  416.     XtSetArg(args[num_args], XtNradioData, "."); num_args++;
  417.     dot = XtCreateManagedWidget("dot", toggleWidgetClass, 
  418.                     form, args, num_args);
  419.     XtAddCallback(dot, XtNcallback, 
  420.               ActivateWidgetsAndSetResourceString,(XtPointer) node);
  421.  
  422.     num_args = 0;
  423.     XtSetArg(args[num_args], XtNfromHoriz, class); num_args++;
  424.     XtSetArg(args[num_args], XtNfromVert, dot); num_args++;
  425.     XtSetArg(args[num_args], XtNradioGroup, dot); num_args++;
  426.     XtSetArg(args[num_args], XtNradioData, "*"); num_args++;
  427.     star = XtCreateManagedWidget("star", toggleWidgetClass, 
  428.                      form, args, num_args);
  429.     XtAddCallback(star,XtNcallback, 
  430.               ActivateWidgetsAndSetResourceString, (XtPointer) node);
  431.  
  432.     if (name_info != NULL) {
  433.         name_info->next = (NameInfo *) XtMalloc(sizeof(NameInfo));
  434.         name_info = name_info->next;
  435.     }
  436.     else
  437.         res_box->name_info = 
  438.              name_info = (NameInfo *) XtMalloc(sizeof(NameInfo));
  439.  
  440.     name_info->sep_leader = dot;
  441.     name_info->name_leader = NULL;
  442.  
  443.     if (names[i] != NULL) {
  444.         new_info = (AnyInfo *) XtMalloc(sizeof(AnyInfo));
  445.         new_info->node = node;
  446.         new_info->left_dot = dot;
  447.         new_info->left_star = star;
  448.         new_info->left_count = 0;
  449.         if (old_info != NULL) 
  450.         old_info->right_count = &(new_info->left_count);
  451.     }
  452.     else if (old_info != NULL) 
  453.         old_info->right_count = NULL;
  454.  
  455.     if (old_info != NULL) {
  456.         old_info->right_dot = dot;
  457.         old_info->right_star = star;
  458.  
  459.         XtAddCallback(any, XtNcallback, AnyChosen, (XtPointer) old_info);
  460.         XtAddCallback(any, XtNdestroyCallback, 
  461.               FreeClientData, (XtPointer) old_info);
  462.     }
  463.  
  464.     if ( names[i] == NULL) /* no more name and class boxes. */
  465.         break;
  466.  
  467.     old_info = new_info;
  468.  
  469.     num_args = 0;
  470.     XtSetArg(args[num_args], XtNfromHoriz, dot); num_args++;
  471.     XtSetArg(args[num_args], XtNlabel, names[i]); num_args++;
  472.     XtSetArg(args[num_args], XtNradioData, names[i]); num_args++;
  473.     name = XtCreateManagedWidget("name", toggleWidgetClass, 
  474.                      form, args, num_args);
  475.     XtAddCallback(name,XtNcallback,
  476.               ActivateWidgetsAndSetResourceString,(XtPointer) node);
  477.  
  478.     num_args = 0;
  479.     XtSetArg(args[num_args], XtNfromHoriz, star); num_args++;
  480.     XtSetArg(args[num_args], XtNfromVert, name); num_args++;
  481.     XtSetArg(args[num_args], XtNlabel, classes[i]); num_args++;
  482.     XtSetArg(args[num_args], XtNradioGroup, name); num_args++;
  483.     XtSetArg(args[num_args], XtNradioData, classes[i]); num_args++;
  484.     class = XtCreateManagedWidget("class", toggleWidgetClass, 
  485.                       form,args,num_args);
  486.     XtAddCallback(class, XtNcallback,
  487.               ActivateWidgetsAndSetResourceString,(XtPointer) node);
  488.  
  489.     num_args = 0;
  490.     XtSetArg(args[num_args], XtNfromHoriz, star); num_args++;
  491.     XtSetArg(args[num_args], XtNfromVert, class); num_args++;
  492.     XtSetArg(args[num_args], XtNradioData, "?"); num_args++;
  493.     XtSetArg(args[num_args], XtNradioGroup, name); num_args++;
  494.     single = XtCreateManagedWidget("single", toggleWidgetClass, 
  495.                        form, args, num_args);
  496.     XtAddCallback(single,XtNcallback,
  497.               ActivateWidgetsAndSetResourceString,(XtPointer) node);
  498.  
  499.     num_args = 0;
  500.     XtSetArg(args[num_args], XtNfromHoriz, any); num_args++;
  501.     XtSetArg(args[num_args], XtNfromVert, single); num_args++;
  502.     XtSetArg(args[num_args], XtNradioGroup, name); num_args++;
  503.     XtSetArg(args[num_args], XtNradioData, ANY_RADIO_DATA); num_args++;
  504.     any = XtCreateManagedWidget("any", toggleWidgetClass, 
  505.                     form, args, num_args);
  506.  
  507.     name_info->name_leader = name;
  508.  
  509.     MakeBoxLookNice(dot, star, any, single, name, class,
  510.             (i == 0 ? -1 : (names[i + 1] ? 0 : 1)));
  511.  
  512.     i++;
  513.     }
  514.  
  515.     name_info->next = NULL;
  516.     XtFree((char *)names);        /* Free what you allocate... */
  517.     XtFree((char *)classes);
  518. }
  519.  
  520. /*    Function Name: SetToggleGroupLeaders
  521.  *    Description: Sets the leaders of each toggle group.
  522.  *                 node - The widget node containing this res box.
  523.  *    Returns: none
  524.  */
  525.  
  526. static void
  527. SetToggleGroupLeaders(node)
  528. WNode * node;
  529. {
  530.     NameInfo *name;
  531.     ResourceBoxInfo * res_box = node->resources->res_box;
  532.     static Arg args[] = {
  533.     {XtNstate, (XtArgVal) TRUE}
  534.     };
  535.  
  536.     for (name  = res_box->name_info; name != NULL; name = name->next) {
  537.     XtSetValues(name->sep_leader, args, XtNumber(args));
  538.     if (name->name_leader != NULL)
  539.         XtSetValues(name->name_leader, args, XtNumber(args));
  540.     }
  541.     SetResourceString(NULL, (XtPointer) node, NULL);
  542. }
  543.  
  544. /*    Function Name: MakeBoxLookNice
  545.  *    Description: Resizes the box that contains the resource names
  546.  *                   to look a bit nicer.
  547.  *    Arguments: dot, star - the widgets containing the separator types.
  548.  *                 any, single, name, class - the widgets that contain the
  549.  *                                     name and class of this object.
  550.  *    Returns: none.
  551.  */
  552.  
  553. static void
  554. MakeBoxLookNice(dot, star, any, single, name, class, endbox)
  555. Widget dot, star, any, single, name, class;
  556. int endbox;
  557. {
  558.  
  559. #define MAX_HDIST 3
  560.  
  561.     Arg args[10];
  562.     Cardinal num_args;
  563.     Dimension any_width, name_class_width, dot_star_width;
  564.     Dimension width_1, width_2;
  565.     int h_dist[MAX_HDIST];
  566.     int i;
  567.  
  568.     /*
  569.      * Make sure that the dot and star widgets are the same size.
  570.      */
  571.  
  572.     num_args = 0;
  573.     XtSetArg(args[num_args], XtNhorizDistance, &(h_dist[0])); num_args++;
  574.     XtSetArg(args[num_args], XtNwidth, &width_1); num_args++;
  575.     XtGetValues(dot, args, num_args);
  576.  
  577.     num_args = 0;
  578.     XtSetArg(args[num_args], XtNhorizDistance, &(h_dist[1])); num_args++;
  579.     XtSetArg(args[num_args], XtNwidth, &width_2); num_args++;
  580.     XtGetValues(star, args, num_args);
  581.  
  582.     num_args = 0;
  583.     XtSetArg(args[num_args], XtNhorizDistance, &(h_dist[2])); num_args++;
  584.     XtSetArg(args[num_args], XtNwidth, &any_width); num_args++;
  585.     XtGetValues(any, args, num_args);
  586.     
  587.     dot_star_width = (width_1 > width_2) ? width_1 : width_2;
  588.     for (i = 1 ; i < MAX_HDIST; i++) {
  589.     if (h_dist[i] > h_dist[0]) h_dist[0] = h_dist[i];
  590.     }
  591.  
  592.     num_args = 0;
  593.     XtSetArg(args[num_args], XtNhorizDistance, h_dist[0]); num_args++;
  594.     XtSetValues(any, args, num_args);
  595.     
  596.     /*
  597.      * Add a new arg, and continue...
  598.      */
  599.     XtSetArg(args[num_args], XtNwidth, dot_star_width); num_args++; 
  600.     XtSetValues(star, args, num_args);
  601.     XtSetValues(dot, args, num_args);
  602.  
  603.  
  604.     /*
  605.      * Now make sure that the Any Widget is as wide as the longest
  606.      * of the name and class widgets, plus space for the dot and star widgets.
  607.      * Don't forget the Form widget's internal space.
  608.      */
  609.  
  610.     num_args = 0;
  611.     XtSetArg(args[num_args], XtNwidth, &width_1); num_args++;
  612.     XtSetArg(args[num_args], XtNhorizDistance, &(h_dist[0])); num_args++;
  613.     XtGetValues(name, args, num_args);
  614.  
  615.     num_args = 0;
  616.     XtSetArg(args[num_args], XtNwidth, &width_2); num_args++;
  617.     XtSetArg(args[num_args], XtNhorizDistance, &(h_dist[1])); num_args++;
  618.     XtGetValues(class, args, num_args);
  619.  
  620.     if (width_2 > width_1) width_1 = width_2;
  621.     if (h_dist[1] > h_dist[0]) h_dist[0] = h_dist[1];
  622.  
  623.     num_args = 0;
  624.     XtSetArg(args[num_args], XtNwidth, &width_2); num_args++;
  625.     XtSetArg(args[num_args], XtNhorizDistance, &(h_dist[1])); num_args++;
  626.     XtGetValues(single, args, num_args);
  627.  
  628.     name_class_width = (width_1 > width_2) ? width_1 : width_2;
  629.     if (h_dist[1] > h_dist[0]) h_dist[0] = h_dist[1];
  630.     if (any_width > name_class_width)
  631.     name_class_width = any_width;
  632.     any_width = dot_star_width + h_dist[0] + name_class_width;
  633.     if (endbox < 0)
  634.     any_width += dot_star_width / 2;
  635.     else if (endbox > 0)
  636.     any_width += (dot_star_width - dot_star_width / 2);
  637.  
  638.     num_args = 0;
  639.     XtSetArg(args[num_args], XtNwidth, any_width); num_args++;
  640.     XtSetValues(any, args, num_args);    
  641.  
  642.     num_args = 0;
  643.     XtSetArg(args[num_args], XtNwidth, name_class_width); num_args++;
  644.     XtSetArg(args[num_args], XtNhorizDistance, h_dist[0]); num_args++;
  645.     XtSetValues(name, args, num_args);    
  646.     XtSetValues(class, args, num_args);    
  647.     XtSetValues(single, args, num_args);    
  648. }
  649.  
  650. /*    Function Name: CreateLists
  651.  *    Description: Creates the list widgets for the normal and constraint 
  652.  *                   resources
  653.  *    Arguments: parent - parent of the lists.
  654.  *                 node - The widget node containing this res box.
  655.  *                 names, cons_names - lists for norm and cons resource boxes.
  656.  *    Returns: none
  657.  */
  658.  
  659. static void
  660. CreateLists(parent, node, names, cons_names) 
  661. Widget parent;
  662. WNode * node;
  663. char **names, **cons_names;
  664. {
  665.     Cardinal num_args;
  666.     ResourceBoxInfo * res_box = node->resources->res_box;
  667.     Arg args[1];
  668.  
  669.     (void) XtCreateManagedWidget("namesLabel", labelWidgetClass, 
  670.                  parent, NULL, ZERO);
  671.     
  672.     num_args = 0;
  673.     XtSetArg(args[num_args], XtNlist, names); num_args++;    
  674.     res_box->norm_list = XtCreateManagedWidget("namesList", listWidgetClass, 
  675.                       parent, args, num_args);
  676.     XtAddCallback(res_box->norm_list, XtNcallback, 
  677.           ResourceListCallback, (XtPointer) node);
  678.     XtAddCallback(res_box->norm_list, XtNdestroyCallback, 
  679.           FreeClientData, (XtPointer) names);
  680.  
  681.     if (cons_names != NULL) {
  682.     (void) XtCreateManagedWidget("constraintLabel", labelWidgetClass, 
  683.                      parent, NULL, ZERO);
  684.     
  685.     num_args = 0;
  686.     XtSetArg(args[num_args], XtNlist, cons_names); num_args++;    
  687.     res_box->cons_list = XtCreateManagedWidget("constraintList", 
  688.                            listWidgetClass, 
  689.                            parent, args, num_args);
  690.     XtAddCallback(res_box->cons_list, XtNcallback, 
  691.               ResourceListCallback, (XtPointer) node);
  692.     XtAddCallback(res_box->cons_list, XtNdestroyCallback, 
  693.               FreeClientData, (XtPointer) cons_names);
  694.     }
  695.     else 
  696.     res_box->cons_list = NULL;
  697. }
  698.  
  699. /*    Function Name: CreateValueWidget
  700.  *    Description: Creates the value widget for entering the resources value.
  701.  *    Arguments: parent - parent of this widget.
  702.  *                 res_box - the resource box info.
  703.  *    Returns: none.
  704.  */
  705.  
  706. static void
  707. CreateValueWidget(parent, node)
  708. Widget parent;
  709. WNode * node;
  710. {
  711.     Widget form, label;
  712.     Cardinal num_args;
  713.     Arg args[10];
  714.     ResourceBoxInfo * res_box = node->resources->res_box;
  715.     
  716.     form = XtCreateManagedWidget("valueForm", formWidgetClass,
  717.                  parent, NULL, ZERO);
  718.  
  719.     num_args = 0;
  720.     XtSetArg(args[num_args], XtNleft, XawChainLeft); num_args++;
  721.     XtSetArg(args[num_args], XtNright, XawChainLeft); num_args++;
  722.     XtSetArg(args[num_args], XtNtop, XawChainTop); num_args++;
  723.     XtSetArg(args[num_args], XtNbottom, XawChainBottom); num_args++;
  724.     label = XtCreateManagedWidget("valueLabel", labelWidgetClass, 
  725.                  form, args, num_args);
  726.  
  727.     num_args = 0;
  728.     XtSetArg(args[num_args], XtNfromHoriz, label); num_args++;
  729.     XtSetArg(args[num_args], XtNleft, XawChainLeft); num_args++;
  730.     XtSetArg(args[num_args], XtNright, XawChainRight); num_args++;
  731.     XtSetArg(args[num_args], XtNtop, XawChainTop); num_args++;
  732.     XtSetArg(args[num_args], XtNbottom, XawChainBottom); num_args++;
  733.     res_box->value_wid = XtCreateManagedWidget("valueText", 
  734.                            asciiTextWidgetClass, 
  735.                            form, args, num_args);
  736. #ifdef notdef
  737.     XtAddCallback(XawTextGetSource(res_box->value_wid), XtNcallback,
  738.           SetResourceString, (XtPointer) node);
  739. #endif
  740. }
  741.  
  742. /*    Function Name: PopupOnNode
  743.  *    Description: Pops a shell widget up centered on the node specified.
  744.  *    Arguments: node - the node.
  745.  *                 shell - the shell to popup.
  746.  *    Returns: none.
  747.  */
  748.  
  749. extern Atom wm_delete_window;
  750.  
  751. static void
  752. PopupOnNode(node, shell)
  753. WNode * node;
  754. Widget shell;
  755. {
  756.     Arg args[3];
  757.     Cardinal num_args;
  758.     Position x, y;
  759.     Dimension width, height, bw;
  760.  
  761.     num_args = 0;
  762.     XtSetArg(args[num_args], XtNwidth, &width); num_args++;
  763.     XtSetArg(args[num_args], XtNheight, &height); num_args++;
  764.     XtSetArg(args[num_args], XtNborderWidth, &bw); num_args++;
  765.     XtGetValues(node->widget, args, num_args);
  766.     XtTranslateCoords(node->widget, 
  767.               (Position) (width/2 + bw), (Position) (height/2 + bw),
  768.               &x, &y);
  769.     
  770.     XtOverrideTranslations
  771.       (shell, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
  772.     XtRealizeWidget(shell);
  773.     wm_delete_window = XInternAtom(XtDisplay(shell), "WM_DELETE_WINDOW",
  774.                    False);
  775.     (void) XSetWMProtocols (XtDisplay(shell), XtWindow(shell),
  776.                             &wm_delete_window, 1);
  777.     XtGetValues(shell, args, num_args);    /* use same arg_list. */
  778.  
  779.     x -= (Position) (width/2 + bw);
  780.     y -= (Position) (height/2 + bw);
  781.  
  782.     if (x < 0)
  783.     x = 0;
  784.     else {
  785.     Position max_loc = WidthOfScreen(XtScreen(shell)) - 
  786.                          (Position) (width + 2 * bw);
  787.     if (x > max_loc)
  788.         x = max_loc;
  789.     }
  790.  
  791.     if (y < 0) 
  792.     y = 0;
  793.     else {
  794.     Position max_loc = HeightOfScreen(XtScreen(shell)) - 
  795.                          (Position) (height + 2 * bw);
  796.     if (y > max_loc)
  797.         y = max_loc;
  798.     }
  799.  
  800.     num_args = 0;
  801.     XtSetArg(args[num_args], XtNx, x); num_args++;
  802.     XtSetArg(args[num_args], XtNy, y); num_args++;
  803.     XtSetValues(shell, args, num_args);
  804.  
  805.     XtPopup(shell, XtGrabNone);
  806. }
  807.  
  808. /*    Function Name: FreeClientData
  809.  *    Description: Frees the client data passed to this function.
  810.  *    Arguments: w - UNUSED.
  811.  *                 list_ptr - pointer to the list to check.
  812.  *                 junk - UNUSED.
  813.  *    Returns: none
  814.  */
  815.  
  816. /* ARGSUSED */
  817. static void
  818. FreeClientData(w, ptr, junk)
  819. Widget w;
  820. XtPointer ptr, junk;
  821. {
  822.     XtFree(ptr);
  823. }
  824.  
  825. /*    Function Name: FreeResBox.
  826.  *    Description: Frees resource box allocated memory.
  827.  *    Arguments: w - UNUSED.
  828.  *                 ptr - pointer to the node that has this resources box.
  829.  *                 junk - UNUSED.
  830.  *    Returns: none
  831.  */
  832.  
  833. /* ARGSUSED */
  834. static void
  835. FreeResBox(w, ptr, junk)
  836. Widget w;
  837. XtPointer ptr, junk;
  838. {
  839.     WNode * node = (WNode *) ptr;
  840.     NameInfo *old_name, *name = node->resources->res_box->name_info;
  841.     
  842.     global_resource_box_up = FALSE;
  843.  
  844.     XtFree((XtPointer) node->resources->res_box);
  845.     node->resources->res_box = NULL;
  846.  
  847.     while (name != NULL) {
  848.     old_name = name;
  849.     name = name->next;
  850.     XtFree((XtPointer) old_name);
  851.     } 
  852. }
  853.  
  854.  
  855.     
  856.